package com.gooagoo.supercrm.ui.activity.login;

import android.text.TextUtils;

import com.gooagoo.supercrm.base.BaseView;
import com.gooagoo.supercrm.base.RxPresenter;
import com.gooagoo.supercrm.tinker.SampleApplicationLike;

import java.util.concurrent.TimeUnit;

import io.reactivex.internal.operators.observable.ObservableDelay;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

public class LoginPresenterImpl extends  RxPresenter implements LoginContract.Presenter{

    @Override
    public void login(String username, String password) {
        if(TextUtils.isEmpty(username) || TextUtils.isEmpty(password) ){
            mView.showToast("用户名密码不能为空");
            return;
        }
        if ("admin".equals(username) && "123456".equals(password)){
            LoginContract.View view = (LoginContract.View) mView;
            mView.showLoading();
            Observable.timer(2, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {
                @Override
                public void call(Long aLong) {
                    mView.hideLoading();
                    view.toHome();
                }
            });

        }else {
            mView.showErr();
        }

    }
}
